package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author 东哥
 * @since 2025-10-18
 */
@Api(tags = "我的课程相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService lessonService;

    /**
     * 1、分页查询我的课表（Day2 - 课堂2）
     * @param pageQuery
     * @return
     */

    @GetMapping("page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> pageQueryMyLessons(PageQuery pageQuery){
        return lessonService.pageQueryMyLessons(pageQuery);
    }

    /**
     * 2、查询我正在学习的课程 (Day2- 作业1)
     * @return
     */
    @GetMapping("/now")
    @ApiOperation("查询我正在学习的课程")
    public LearningLessonVO queryMyCurrentLesson() {
        return lessonService.queryMyCurrentLesson();
    }

    /**
     * 3、查询指定课程信息 (Day2- 作业2)
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}")
    @ApiOperation("查询指定课程信息")
    public LearningLessonVO queryLessonByCourseId(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        return lessonService.queryLessonByCourseId(courseId);
    }

    /**
     * 4、删除指定课程信息 (Day2- 作业3)
     * @return
     */
    @DeleteMapping("/{courseId}")
    @ApiOperation("删除指定课程信息")
    public void deleteCourseFromLesson(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        lessonService.deleteCourseFromLesson(null, List.of(courseId));
    }

    /**
     * 5、统计课程学习人数 (Day2- 作业4)
     * @return
     */
    @ApiOperation("统计课程学习人数")
    @GetMapping("/{courseId}/count")
    public Integer countLearningLessonByCourse(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId){
        return lessonService.countLearningLessonByCourse(courseId);
    }

    /**
     * 6、校验当前课程是否已经报名 (Day2- 作业5)
     * @return
     */
    @ApiOperation("校验当前课程是否已经报名")
    @GetMapping("/{courseId}/valid")
    public Long isLessonValid(
            @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        return lessonService.isLessonValid(courseId);
    }

    /**
     * 7、创建或修改学习计划 (Day3- 课堂3)
     * @param planDTO
     */
    @ApiOperation("创建或修改学习计划")
    @PostMapping("plans")
    public void createPlans(@RequestBody LearningPlanDTO planDTO){
        lessonService.createPlans(planDTO);
    }

    /**
     * 8、查询我的学习计划 (Day3- 课堂4)
     * @param pageQuery
     */
    @ApiOperation("查询我的学习计划")
    @GetMapping("plans")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery){
        return lessonService.queryMyPlans(pageQuery);
    }
}
